package cn.net.xyan.blossom.webUI.entity

import cn.net.xyan.blossom.kotlin.NoArg
import cn.net.xyan.blossom.security.entity.SecurityPermission
import java.util.*
import javax.persistence.*

@MappedSuperclass
abstract class ComparableEntity<T : ComparableEntity<T>> : Comparable<T?> {
    var order: Int = 0
    override fun compareTo(other: T?): Int {
        return order.compareTo(other?.order ?: 0)
    }
}


@Entity
@Table(name = "sys_catalog")
@NoArg
data class Catalog(@Id val code: String, var title: String) : ComparableEntity<Catalog>() {

    var permission: SecurityPermission? = null

    @OneToMany(mappedBy = "catalog")
    var items:MutableList<CatalogItem> = LinkedList()
}

@Entity
@Table(name = "sys_catalog_item")
@NoArg
class CatalogItem(@Id val itemCode: String,var title: String) : ComparableEntity<CatalogItem>(){
    var permission: SecurityPermission? = null

    @ManyToOne
    @JoinColumn(name = "catalog")
    var catalog:Catalog? = null

    var viewName:String? = null

    var viewParam:String? = null
}